#ifndef _MYDEFINE_H
#define _MYDEFINE_H


#include "stm32f10x.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>

extern uint16_t MSG;
/*
 -----------------------------------------------------
|  MSG  |	               FUNCTION                   |
|-------+---------------------------------------------|_
| bit15 | SET TRUE IF A MSG FROM SIM800A IS RECEIVED  |	\
|-------+---------------------------------------------|  |
| bit14 | SET TRUE IF A MSG FROM CAMERA1 IS RECEIVED  |  |
|-------+---------------------------------------------|   \  EXECUTE THESE FOUR
| bit13 | SET TRUE IF A MSG FROM CAMERA2 IS RECEIVED  |		/  MESSAGES FIRST
|-------+---------------------------------------------|	 |
| bit12 | SET TRUE IF A/D CONVERTER NEEDS TO WORK     |  |
|-------+---------------------------------------------|_/
| bit11 | 
|-------+---------------------------------------------|
| bit10 |
|-------+---------------------------------------------|
| bit09 |
|-------+---------------------------------------------|
| bit08 |
|-------+---------------------------------------------|
| bit07 |
|-------+---------------------------------------------|
| bit06 |
|-------+---------------------------------------------|
| bit05 |
|-------+---------------------------------------------|
| bit04 |
|-------+---------------------------------------------|
| bit03 |
|-------+---------------------------------------------|
| bit02 |
|-------+---------------------------------------------|
| bit01 |
|-------+---------------------------------------------|
| bit00 |
 -------+---------------------------------------------|
*/



#define SETSIM800AMSG() (MSG |= 0x8000)
#define RESETSIM800AMSG() (MSG &= 0x7FFF)
#define SETCAMERA1MSG() (MSG |= 0x4000)
#define RESETCAMERA1MSG() (MSG &= 0xBFFF)
#define SETCAMERA2MSG() (MSG |= 0x2000)
#define RESETCAMERA2MSG() (MSG &= 0xDFFF)




extern uint16_t COUNTER;
extern unsigned long Sysus;
extern unsigned long Sysms;
extern uint16_t Buffer_flg1;
extern uint16_t Buffer_flg2;
extern uint16_t Buffer_flg3;
extern uint8_t Rcv_buffer1[];
extern uint8_t Rcv_buffer2[];
extern uint8_t Rcv_buffer3[];




#define FAIL 0
#define SUCCESS 1
#define BUFFERSIZE 1030
#define CmdSIM800 Cmd_Send1
#define GPRSSend Usart1Send
#define CmdCamera1 Cmd_Send2
#define CmdCamera2 Cmd_Send3
#define BUFFERSIZESIM800A 80
#define SendSIM800 Usart1Send
#define SendCamera1 Usart2Send
#define SendCamera2 Usart3Send
#define delay1s() Delayms(1000)
#define ACKCMD 6, 0xAA, 0x0D, 0x00, 0x00, 0x00, 0x00
#define IMGCMD 6, 0xAA, 0x04, 0x05, 0x00, 0x00, 0x00
#define INITCMD 6, 0xAA, 0x01, 0X00, 0x07, 0x00, 0x07
#define DATASIZECMD 6, 0xAA, 0x06, 0x08, 0x20, 0x03, 0x00
#define delay3s() Delayms(1000);Delayms(1000);Delayms(1000)
#define delay5s() Delayms(1000);Delayms(1000);Delayms(1000);Delayms(1000);Delayms(1000)




void MSGHandle(void);
void Camera1Init(void);
void Camera2Init(void);
void SIM800AInit(void);
void Debug(const char*);
void SIM800Handler(void);
void Camera1Handler(void);
void Camera2Handler(void);
void Cmd_Send1(char, ...);
void Cmd_Send2(char, ...);
void Cmd_Send3(char, ...);
void LOCALPeriphInit(void);
void Delayus(unsigned long);
void Delayms(unsigned long);  // <=1864ms
uint32_t Camera1Snapshot(void);
uint32_t Camera2Snapshot(void);
void Camera1ImageProcess(void);
void Camera2ImageProcess(void);
//uint8_t GPRSSend(const char *, uint16_t);
void Usart1Send(const char *, const uint16_t);
void Usart2Send(const char *, const uint16_t);
void Usart3Send(const char *, const uint16_t);




#endif


